1 const assert
= require( 'assert' ),
2 HistoryPage
= require( '../pageobjects/history.page' ),
3 UserLoginPage
= require( 'wdio-mediawiki/LoginPage' ),
4 Util
= require( 'wdio-mediawiki/Util' );
6 describe( 'Rollback with confirmation', function () {
11 // disable VisualEditor welcome dialog
12 browser
.deleteCookie();
14 browser
.localStorage( 'POST', { key
: 've-beta-welcome-dialog', value
: '1' } );
16 // Enable rollback confirmation for admin user
17 // Requires user to log in again, handled by deleteCookie() call in beforeEach function
18 UserLoginPage
.loginAdmin();
20 UserLoginPage
.waitForScriptsToBeReady();
21 browser
.execute( function () {
22 return ( new mw
.Api() ).saveOption(
23 'showrollbackconfirmation',
29 beforeEach( function () {
30 browser
.deleteCookie();
32 content
= Util
.getTestString( 'beforeEach-content-' );
33 name
= Util
.getTestString( 'BeforeEach-name-' );
35 HistoryPage
.vandalizePage( name
, content
);
37 UserLoginPage
.loginAdmin();
38 HistoryPage
.open( name
);
41 it( 'should offer rollback options for admin users', function () {
42 assert
.strictEqual( HistoryPage
.rollback
.getText(), 'rollback 1 edit' );
44 HistoryPage
.rollback
.click();
46 assert
.strictEqual( HistoryPage
.rollbackConfirmable
.getText(), 'Please confirm:' );
47 assert
.strictEqual( HistoryPage
.rollbackConfirmableYes
.getText(), 'Rollback' );
48 assert
.strictEqual( HistoryPage
.rollbackConfirmableNo
.getText(), 'Cancel' );
51 it( 'should offer a way to cancel rollbacks', function () {
52 HistoryPage
.rollback
.click();
54 HistoryPage
.rollbackConfirmableNo
.waitForVisible( 5000 );
56 HistoryPage
.rollbackConfirmableNo
.click();
58 browser
.pause( 1000 ); // Waiting to ensure we are NOT redirected and stay on the same page
60 assert
.strictEqual( HistoryPage
.heading
.getText(), 'Revision history of "' + name
+ '"' );
63 it( 'should perform rollbacks after confirming intention', function () {
64 HistoryPage
.rollback
.click();
66 HistoryPage
.rollbackConfirmableYes
.waitForVisible( 5000 );
68 HistoryPage
.rollbackConfirmableYes
.click();
70 // waitUntil indirectly asserts that the content we are looking for is present
71 browser
.waitUntil( function () {
72 return browser
.getText( '#firstHeading' ) === 'Action complete';
73 }, 5000, 'Expected rollback page to appear.' );
76 it( 'should verify rollbacks via GET requests are confirmed on a follow-up page', function () {
77 var rollbackActionUrl
= HistoryPage
.rollbackLink
.getAttribute( 'href' );
78 browser
.url( rollbackActionUrl
);
80 browser
.waitUntil( function () {
81 return HistoryPage
.rollbackNonJsConfirmable
.getText() === 'Revert edits to this page?';
82 }, 5000, 'Expected rollback confirmation page to appear for GET-based rollbacks.' );
84 HistoryPage
.rollbackNonJsConfirmableYes
.click();
86 browser
.waitUntil( function () {
87 return browser
.getText( '#firstHeading' ) === 'Action complete';
88 }, 5000, 'Expected rollback page to appear.' );
93 describe( 'Rollback without confirmation', function () {
98 // disable VisualEditor welcome dialog
99 browser
.deleteCookie();
100 UserLoginPage
.open();
101 browser
.localStorage( 'POST', { key
: 've-beta-welcome-dialog', value
: '1' } );
103 // Disable rollback confirmation for admin user
104 // Requires user to log in again, handled by deleteCookie() call in beforeEach function
105 UserLoginPage
.loginAdmin();
107 UserLoginPage
.waitForScriptsToBeReady();
108 browser
.execute( function () {
109 return ( new mw
.Api() ).saveOption(
110 'showrollbackconfirmation',
116 beforeEach( function () {
117 browser
.deleteCookie();
119 content
= Util
.getTestString( 'beforeEach-content-' );
120 name
= Util
.getTestString( 'BeforeEach-name-' );
122 HistoryPage
.vandalizePage( name
, content
);
124 UserLoginPage
.loginAdmin();
125 HistoryPage
.open( name
);
128 it( 'should perform rollback via POST request without asking the user to confirm', function () {
129 HistoryPage
.rollback
.click();
131 // waitUntil indirectly asserts that the content we are looking for is present
132 browser
.waitUntil( function () {
133 return HistoryPage
.headingText
=== 'Action complete';
134 }, 5000, 'Expected rollback page to appear.' );
137 it( 'should perform rollback via GET request without asking the user to confirm', function () {
138 var rollbackActionUrl
= HistoryPage
.rollbackLink
.getAttribute( 'href' );
139 browser
.url( rollbackActionUrl
);
141 browser
.waitUntil( function () {
142 return browser
.getText( '#firstHeading' ) === 'Action complete';
143 }, 5000, 'Expected rollback page to appear.' );